//
// Created by xili on 2024/9/26 14:53.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int MOD = 1e9 + 7;

    int countNicePairs(vector<int> &nums) {
        unordered_map<int, int> ump;
        int n = nums.size();
        ump[nums[0] - f(nums[0])]++;
        int ans = 0;
        for (int i = 1; i < n; i++) {
            int t = nums[i] - f(nums[i]);
            ans = (ans + (ump.count(t) ? ump[t] : 0)) % MOD;
            ump[t]++;
        }
        return ans;
    }

    int f(int n) {
        int res = 0;
        while (n) {
            res = res * 10 + n % 10;
            n /= 10;
        }
        return res;
    }
};